package 正则;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexTelDemo {
    public static void main(String[] args) {
//        "^(((13|18)[0-9]{9}) )"
        String regTel = "^1[3456789]\\d{9}$";
        System.out.println("请输入电话号码：");
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        Pattern p = Pattern.compile(regTel);
        Matcher m = p.matcher(str);
        if(m.find()){
            System.out.println(m.start()  + "--------" + m.end());
            System.out.println("电话号码正确，电话号码为: "+m.group());
        }else{
            System.out.println("电话号码格式不正确");
        }
    }
}
